<script setup lang="ts">
	import Menu from './layout/aside/Menu.vue'
	import Header from './layout/header/index.vue'
	import Footer from './layout/footer/index.vue'
  import {computed,  onMounted, onUnmounted, ref} from "vue";
  import {useSettingStore} from "@/stores/setting.ts";
  const SettingStore = useSettingStore()
  const isCollapse = computed(() =>!SettingStore.isCollapse)
  const asideWidth = ref<number>(210);
  let isResizing = false;
  let startX = 0;
  let startWidth = 0;

  const startResizing = (event: MouseEvent) => {
	isResizing = true;
	startX = event.clientX;
	startWidth = asideWidth.value;

	document.addEventListener("mousemove", resizeAside);
	document.addEventListener("mouseup", stopResizing);
  };

  const resizeAside = (event: MouseEvent) => {
	if (isResizing) {
	  const newWidth = startWidth + (event.clientX - startX);
	  asideWidth.value = newWidth > 50 ? newWidth : 50; // 设置最小宽度为 50px
	}
  };

  const stopResizing = () => {
	isResizing = false;
	document.removeEventListener("mousemove", resizeAside);
	document.removeEventListener("mouseup", stopResizing);
  };

  onMounted(() => {
	document.addEventListener("mouseup", stopResizing);
  });

  onUnmounted(() => {
	document.removeEventListener("mouseup", stopResizing);
  });
</script>
<style scoped>
	.common-layout{
		display: flex;
		width:100wh;
		height:97vh;
		.el-container{
      background-color: var(--color-background);
			.el-aside{
				background-color: var(--color-background);
				width: auto;
				text-align: center;
				display: flex;
        height: 98%;
			}
			.el-aside::-webkit-scrollbar{
				display: none;
			}
			.main{
        background-color: var(--color-background);
				.el-header{
          background-color: var(--color-background);
					align-items: center;
					display: flex;
					height: 12%;
					padding-left: 1px;
				}
				.el-main{
          width: 100%;
          background-color: var(--color-background);
					height:83%;
				}
				.el-footer{
          background-color: var(--color-background);
					align-items: center;
					justify-content: center;
					display: flex;
					height: 5%;
				}
			}
		}
	}
	.m-drag{
	    background-color: lightgray;
	    width: 2px;
	    height: 100%;
	    cursor: pointer;
	  }
  .el-main-card{
    overflow: auto;
  }
  .el-main-card::-webkit-scrollbar{
    display: none;
  }
</style>
<template>
	<div class="common-layout">
	    <el-container class="el-container">
	      <el-aside class="el-aside">
			  <div class="aside-box" :style="{ width: isCollapse ? '1px' : asideWidth + 'px' }">
				  <Menu/>
			  </div>
			  <div class="m-drag" @mousedown="startResizing"></div>
		  </el-aside>
	      <el-container class="el-container main">
	        <el-header class="el-header">
				<Header></Header>
			</el-header>
	        <el-main class="el-main">
            <el-card class="el-main-card" style="width: 100%;height: 100%;">
              <router-view>
              </router-view>
            </el-card>
			    </el-main>
	        <el-footer class="el-footer" v-if="false">
				<Footer></Footer>
			</el-footer>
	      </el-container>
	    </el-container>
	</div>
</template>


